package telcoGUI.messageHandler;

import java.util.Collection;

import swa2012.telco.broker.beans.Message;
import telcoClient.client.IncomingMessageHandler;
import telcoGUI.userInterface.TelcoClientGUI;

public class TelcoGUIMessageHandler implements IncomingMessageHandler
{
	private TelcoClientGUI telcoGUI;
	
	public TelcoGUIMessageHandler(TelcoClientGUI telcoGUI)
	{
		this.telcoGUI = telcoGUI;
	}
	
	@Override
	public void executeIncomingMessagesAction(Collection<Message> paramMessages)
	{
		StringBuffer stringBuffer = new StringBuffer(this.telcoGUI.getReceivedMessagesTextArea().getText());
		
		for (Message message : paramMessages) {
			stringBuffer.append("Von :" + message.getSender().getID() + "Von Provider:" + message.getSender().getProvider().getID());
			stringBuffer.append(": \n");
			stringBuffer.append(message.getText());
			stringBuffer.append("\n");
		}
		
		this.telcoGUI.getReceivedMessagesTextArea().setText(stringBuffer.toString());	
	}
	
}
